<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>设置</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <style type="text/css">
        .aui-list-item-right{
        	width:4rem;margin-top:0.75rem;
        }
    </style>
</head>
<body>
    <header class="aui-bar aui-bar-nav" id="aui-header" style="padding-top:20px;">
        <a class="aui-btn aui-pull-left" tapmode onclick="closeWin()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">设置</div>
    </header>
    <div class="aui-content aui-margin-b-15 aui-margin-t-15">
        <ul class="aui-list aui-list-in">
            <li class="aui-list-item">
                <div class="aui-list-item-label-icon">
                    <i class="aui-iconfont aui-icon-my"></i>
                </div>
                <div id="uname_id" class="aui-list-item-inner">
                    	用户名
                </div>
            </li>
            <li class="aui-list-item" id="settime_id" onclick="openWin('set_time')">
                <div class="aui-list-item-label-icon">
                    <i class="aui-iconfont aui-icon-date"></i>
                </div>
                <div class="aui-list-item-inner">
                    	设置上班时间
                </div>
            </li>
            <li class="aui-list-item" onclick="clearCach()" >
                <div class="aui-list-item-label-icon">
                    <i class="aui-iconfont aui-icon-trash"></i>
                </div>
                <div class="aui-list-item-inner">
                    	清除缓存
                </div>
                <div class="aui-list-item-right" id="cache_id"></div>
            </li>
        </ul>
    </div>
    <div class="aui-content aui-margin-b-15">
        <ul class="aui-list aui-list-in">
            <li class="aui-list-item" onclick="openWin('send_idea')">
                <div class="aui-list-item-label-icon">
                    <i class="aui-iconfont aui-icon-mail"></i>
                </div>
                <div class="aui-list-item-inner">
                    意见反馈
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-label-icon">
                    <i class="aui-iconfont aui-icon-star"></i>
                </div>
                <div class="aui-list-item-inner">
                    为邦建云办公评分
                </div>
            </li>
            <li class="aui-list-item" onclick="openWin('app_info')">
                <div class="aui-list-item-label-icon">
                    <i class="aui-iconfont aui-icon-info"></i>
                </div>
                <div class="aui-list-item-inner">
                    关于
                </div>
            </li>
        </ul>
    </div>
    <div id="logout_id" style="display: block" class="aui-content aui-margin-l-15 aui-margin-r-15">
    <div class="aui-btn aui-btn-danger aui-btn-block aui-btn-sm " onclick="logout()">退出登陆</div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js" ></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/aui-toast.js" ></script>
<script type="text/javascript">
    var toast = new auiToast();
    apiready = function () {
      $('#settime_id').hide();
    	var uname = $api.getStorage('username');
      document.getElementById('uname_id').innerHTML = uname;
      if(uname=="1001"){
          $('#settime_id').show();
      }
    	//获取缓存大小
    	api.getCacheSize({
	        sync:false
        },function(ret,err){
        	var size = ret.size/1024/1024;
        	//alert(size.toFixed(2));
        	document.getElementById('cache_id').innerHTML = '<font color = "#039be5">'+size.toFixed(2)+'M</font>';

        });
    }

	function clearCach(){
		api.clearCache({
        },function(ret,err){
        	  document.getElementById('cache_id').innerHTML = '<font color = "#039be5">0.00M</font>';
        	  /*api.toast({
	            msg:'清除完成'
            });*/
            toast.success({
								title:"清除完成",
								duration:2000
						});
        });
	}



    function openWin(frame){
        api.openWin({
            name: frame,
            url: frame + '_win.html',
            pageParam: {
                name: name
            },
            rect: {
                x: 0,
                y: 0,
                w: 'auto',
                h: 'auto'
            }
        });
    }

	function logout(){
		// 解绑推送
        var push = api.require('push');
        push.unbind({
            userName:$api.getStorage('cn_name'),
            userId:$api.getStorage('username')
        },function(ret,err){
            if(ret.status){
                // api.alert({msg:'解除绑定成功'});
            }else{
                // api.alert({msg:err.msg});
            }
        });

        $api.setStorage('cn_name', '');
    		$api.setStorage('username', '');
    		$api.setStorage("phone", '');
        $api.setStorage('user_img', '');
        $api.setStorage("ryToken", '');
        $api.setStorage('ryId', '');
        api.sendEvent({
            name:'disconnect',
            extra:{
            }
        });
        api.openWin({
              name: 'login',
              url: 'login_win.html',
              slidBackEnabled: false,
        });
    }


    function closeWin(){
        api.closeWin({
            name: 'setting'
        });
    }
</script>
</html>
